#include "StdAfx.h"
#include "ustringutils.h"
#include "DBFQuoteAdapter.h"
#include "tinyxml.h"
#include "tconfigsetting.h"
#include "umaths.h"


USING_LIBSPACE
namespace quoteadapter
{
	namespace dbf
	{
		CDBFQuoteAdapter::CDBFQuoteAdapter(void)
		{
		}



		CDBFQuoteAdapter::~CDBFQuoteAdapter(void)
		{
		}

		bool CDBFQuoteAdapter::InitializeByXML( const TCHAR* fpath )
		{
			TConfigSetting setting;
			bool ret = setting.LoadConfig(fpath);

			CDBFQuoteParam param[2];
			const char* keys[] = {"sh","sz"};

			for(int i=0; i<2; ++i)
			{
				bool enbled = setting["configuration"][keys[i]]["enabled"].EleVal() == "true";
				std::string path = setting["configuration"][keys[i]]["path"].EleVal();
				std::string interval = setting["configuration"][keys[i]]["interval"].EleVal();
				param[i].m_Enabled = enbled;			
				param[i].m_Path = path;			
				param[i].m_Interval = UMaths::ToInt32(interval);
				tstring timespan = UStrConvUtils::ToTS( setting["configuration"][keys[i]]["timespan"].EleVal() ); 
				tstrings vec;
				USOpeUtils::Split(&vec,timespan,_T(","));
				for(unsigned int i=0; i<vec.size(); ++i)
				{
					tstrings tivec;
					USOpeUtils::Split(&tivec,vec[i],_T("-"));
					std::pair<int,int> data = std::make_pair<int,int>(UMaths::ToInt32(tivec[0]),UMaths::ToInt32(tivec[1]));				
					param[i].m_TimeSpan.push_back(data);
					tstring holidays = UStrConvUtils::ToTS(setting["configuration"][keys[i]]["holiday"].EleVal() );
				}
				

			}




			ret = Initialize(&param);
			return true;
		}

		bool CDBFQuoteAdapter::Initialize( void* param )
		{
			CDBFQuoteParam* params =  (CDBFQuoteParam*)param;

			m_2003parser.svc();
			return true;
		}

		void CDBFQuoteAdapter::UnInitialize()
		{

		}


	};
};